<?php
/**
 * 幻灯片控制器
 * @author maniac
 */
namespace app\manage\controller;

use app\common\model\SlideCategory;
use app\facade\Forms;
use app\common\service\Fields;
class Slides extends Base
{
    /**
     * 首页补充
     * @param array $data 列表信息
     */
    public function indexAttach($data)
    {
        $this->categories();
    }
    
    /**
     * 添加/编辑补充
     * @param array $info 信息
     */
    public function addAttach($info)
    {
        $fields = Fields::rowss([['f', 'eq', 'area']], 'id,fname');
        $enter  = [];
        $fname  = [];
        foreach ($fields as $field) {
            $enter[] = $field['id'];
            $fname[$field['id']] = $field['fname'];
        }
        $html = Forms::generateHtmls('area', $info, $enter, [], $fname,'f');
        $this->assign('html', $html);
        $this->categories();
    }
    
    /**
     * where 查询条件
     * @return [type] [description]
     */
    public function where()
    {
        $category_id = input('get.category_id/d', 0);
        $province=input('province/d','-1');
        $city=input('city/d','-1');
        $district=input('district/d','-1');
        $where =array();
        if ($category_id) {
            $where[] = [
                ['category_id', 'eq', $category_id],
            ];
        }
        if ($province != -1) {
            $where[] = [
                ['province', 'eq', $province],
            ];
        }

        if ($city != -1) {
            $where[] = [
                ['city', 'eq', $city],
            ];
        }

        if ($district != -1) {
            $where[] = [
                ['district', 'eq', $district],
            ];
        }
        return $where;
    }
    
    /**
     * 获取所有幻灯片分类
     */
    private function categories()
    {
        $categories = SlideCategory::field('id,name')->order('id ASC')->select();
        $this->assign('categories', $categories);
    }
}
